package com.ruoyi.web.controller.course;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.SysCourseTopic;
import com.ruoyi.course.service.ISysCourseTopicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程题目Controller
 * 
 * @author yjf
 * @date 2023-05-31
 */
@RestController
@RequestMapping("/courseTopic")
public class SysCourseTopicController extends BaseController
{
    @Autowired
    private ISysCourseTopicService sysCourseTopicService;

    /**
     * 查询课程题目列表
     */
    @PreAuthorize("@ss.hasPermi('courseTopic:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCourseTopic sysCourseTopic)
    {
        startPage();
        List<SysCourseTopic> list = sysCourseTopicService.selectSysCourseTopicList(sysCourseTopic);
        return getDataTable(list);
    }

    /**
     * 导出课程题目列表
     */
    @PreAuthorize("@ss.hasPermi('courseTopic:export')")
    @Log(title = "课程题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCourseTopic sysCourseTopic)
    {
        List<SysCourseTopic> list = sysCourseTopicService.selectSysCourseTopicList(sysCourseTopic);
        ExcelUtil<SysCourseTopic> util = new ExcelUtil<SysCourseTopic>(SysCourseTopic.class);
        util.exportExcel(response, list, "课程题目数据");
    }

    /**
     * 获取课程题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('courseTopic:query')")
    @GetMapping(value = "/{courseTopicId}")
    public AjaxResult getInfo(@PathVariable("courseTopicId") Long courseTopicId)
    {
        return AjaxResult.success(sysCourseTopicService.selectSysCourseTopicByCourseTopicId(courseTopicId));
    }

    /**
     * 新增课程题目
     */
    @PreAuthorize("@ss.hasPermi('courseTopic:add')")
    @Log(title = "课程题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCourseTopic sysCourseTopic)
    {
        return toAjax(sysCourseTopicService.insertSysCourseTopic(sysCourseTopic));
    }

    /**
     * 修改课程题目
     */
    @PreAuthorize("@ss.hasPermi('courseTopic:edit')")
    @Log(title = "课程题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCourseTopic sysCourseTopic)
    {
        return toAjax(sysCourseTopicService.updateSysCourseTopic(sysCourseTopic));
    }

    /**
     * 删除课程题目
     */
    @PreAuthorize("@ss.hasPermi('courseTopic:remove')")
    @Log(title = "课程题目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{courseTopicIds}")
    public AjaxResult remove(@PathVariable Long[] courseTopicIds)
    {
        return toAjax(sysCourseTopicService.deleteSysCourseTopicByCourseTopicIds(courseTopicIds));
    }
}
